//
//  ViewController.m
//  keke
//
//  Created by 张帅 on 16/1/7.
//  Copyright © 2016年 ZhangShuai. All rights reserved.
//

#import "ViewController.h"
#import "KCTableViewCell.h"
#import "ZsModel.h"

#import "MJExtension.h"
@interface ViewController ()<UITableViewDataSource,UITableViewDelegate>

@property(nonatomic,strong) NSArray *cars;
@end


@implementation ViewController
-(NSArray *)cars{
    
    if (_cars==nil) {
        _cars=[NSMutableArray array];
        
    }
    return _cars;
}


- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view, typically from a nib.
    
    self.cars=[ZsModel objectArrayWithFilename:@"ZsModel.plist"];
    //    self.cars=[ZsModel objectArrayWithFile:@"];
    
    self.tableView.estimatedRowHeight=34;
    //    self.tableView.rowHeight=200;
    UIView  *view=[[UIView alloc] initWithFrame:CGRectMake(0, 12, 0,40)];
    
    self.tableView.tableHeaderView=view;
    
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}


-(void)viewDidAppear:(BOOL)animated{
    //  [self.tableView reloadData];
}

-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section

{
    return self.cars.count;
}
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    
    
    KCTableViewCell *cell=[tableView dequeueReusableCellWithIdentifier:@"cell"];
    
    //    cell.backgroundColor=[UIColor redColor];
    
    ZsModel *model=self.cars[indexPath.row];
    cell.model=model;
    return cell;
}


-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    
    
    
    KCTableViewCell *cell=[tableView dequeueReusableCellWithIdentifier:@"cell"];
    
    ZsModel *model=self.cars[indexPath.row];
    if (model.rowHeight) {
        NSLog(@"  缓冲行高%lf",model.rowHeight);
        return model.rowHeight;
    }
    
    CGFloat  height =[cell rowHeightModel:model];
    model.rowHeight= height;
    
    
    return height;
}




@end
